﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ISRecord.View.ViewsModel;
using WpfControls =  Microsoft.Windows.Controls;

namespace ISRecord.View.Views
{
    /// <summary>
    /// Interaction logic for ExcelImportView.xaml
    /// </summary>
    public partial class ExcelImportView : UserControl
    {
        public ExcelImportView()
        {
            InitializeComponent();
        }

        private void WizardFinish(object sender, RoutedEventArgs e)
        {
            BulkOutboxViewModel vm = null;
            try
            {
               vm = DataContext as BulkOutboxViewModel;
                if (vm != null)
                {
                    vm.SaveCommand.Execute(null);
                    excelImportWizard.CurrentPage = (WpfControls.WizardPage)excelImportWizard.FindName("IntroPage");
                }
            }
            catch(Exception ex)
            {
                if (vm != null) vm.Reset();
                MessageBox.Show(ex.Message);
            }
           
        }

 

  


        private void ViewLoaded(object sender, RoutedEventArgs e)
        {
            //Console.WriteLine("View Loaded **********");
            var vm = DataContext as BulkOutboxViewModel;
            if (vm != null)
            {
                //Console.WriteLine("Current Wizard Page: {0} **********", excelImportWizard.CurrentPage.Name);
                string name = vm.CurrentWizardPage;
                //Console.WriteLine("Save Wizard Page: {0} *********", name);
                if (string.IsNullOrEmpty(name)) return;
                excelImportWizard.CurrentPage =(WpfControls.WizardPage) excelImportWizard.FindName(name);
            }
        }
        private void WizardLostFocus(object sender, RoutedEventArgs e)
        {
            //Console.WriteLine("Lost Focust ***********");
            var vm = DataContext as BulkOutboxViewModel;
            if (vm != null)
            {
                vm.CurrentWizardPage = excelImportWizard.CurrentPage.Name;
               // Console.WriteLine("Current Wizard Page: {0} *********", vm.CurrentWizardPage);
            }
        }

        
    }
}
